package com.woniuxy.business.config;

import com.rabbitmq.client.Channel;
import com.woniuxy.business.util.WebSocketUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import javax.websocket.Session;
import java.io.IOException;

@Component
public class FailConsumer {

    @RabbitListener(queues = "fail_queue")
    public void receive(Channel channel, Message message) throws IOException {
        String uname = new String(message.getBody(), "utf-8");
        //手动确认消费消息
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        //将结果返回给用户
        Session session = WebSocketUtil.MESSAGEMAP.get(uname);
        WebSocketUtil.sendMessage(session,"优惠券与你擦肩而过~");
    }
}